package com.qf.controller;


import com.qf.pojo.ResultData;
import com.qf.pojo.UserAddr;
import com.qf.service.UserAddrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("address")
@CrossOrigin
public class UserAddrController {
    @Autowired
    private UserAddrService userAddrService;

    @GetMapping("/{userId}")
    public ResultData<UserAddr> all(@PathVariable("userId") Integer userId) {

        System.out.println(userId);
        return userAddrService.findUserAddrByUserId(Integer.toString(userId));
    }

    @DeleteMapping("{addrId}")
    public ResultData<UserAddr> delAddr(@PathVariable Integer addrId) {

        System.out.println(addrId);
        return userAddrService.deleteUserAddrById(Integer.toString(addrId));
    }

    @PutMapping
    public ResultData<UserAddr> updateAddr(@RequestBody UserAddr userAddr) {

        return userAddrService.updateUserAddr(userAddr);
    }

    @PostMapping
    public ResultData<UserAddr> insertAddr(@RequestBody UserAddr userAddr) {

        return userAddrService.insertUserAddr(userAddr);
    }
}
